/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dao;

import com.entity.Admin;
import com.entity.Classes;
import com.entity.Grade;
import com.entity.Student;
import com.entity.StudentClasses;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 *
 * @author DELL
 */
public class GradeDao {
    
    
                private Session session;
    private Transaction transaction;
    private Query query;

    private SessionFactory sessionFactory = null;

    private HibernateTemplate ht = null;

    public void setSessionFactory(SessionFactory sessionFactory) {

        this.sessionFactory = sessionFactory;
    }

    private HibernateTemplate getHibernateTemplate() {
        if (ht == null) {

            ht = new HibernateTemplate(sessionFactory);
        }
        return ht;
    }

    public List getGrade(Integer stid) {

             ApplicationContext ctx = new FileSystemXmlApplicationContext("jwMSys/applicationContext.xml");
        SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");       //创建sessionFactory对象
        Session session = sessionFactory.openSession();

 
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "aaaaaiiiiiiiiiiii3333333333333333333333333331111");
        Query query2 = (Query) session.createQuery("select s,cla from StudentClasses as  s,Classes as cla   where   s.scsId=cla.csId    and s.tstId='" + stid + "'");
        
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "aaaaaiiiiiiiiiiii1111144444444444444444444444444444444441");
       
        
         List gradeList=query2.list();
         return   gradeList;
         
         
         
         }  
    
        public int countSum(Integer stid) {

             ApplicationContext ctx = new FileSystemXmlApplicationContext("jwMSys/applicationContext.xml");
        SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");       //创建sessionFactory对象
        Session session = sessionFactory.openSession();

 
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "aaaaaiiiiiiiiiiii3333333333333333333333333331111");
        Query query2 = (Query) session.createQuery("select s,cla from StudentClasses as  s,Classes as cla   where   s.scsId=cla.csId    and s.tstId='" + stid + "'");
        
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "aaaaaiiiiiiiiiiii1111144444444444444444444444444444444441");
       
        
         List gradeList=query2.list();
         
         int sum=gradeList.size();
         return   sum;
         
         
         
         }  
    
         public List getGrade2(Integer stid,int page) {

             ApplicationContext ctx = new FileSystemXmlApplicationContext("jwMSys/applicationContext.xml");
        SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");       //创建sessionFactory对象
        Session session = sessionFactory.openSession();
               int  pageNum=page;
 
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "aaaaaiiiiiiiiiiii3333333333333333333333333331111");
        Query query2 = (Query) session.createQuery("select s,cla from StudentClasses as  s,Classes as cla   where   s.scsId=cla.csId    and s.tstId='" + stid + "'");
        
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "aaaaaiiiiiiiiiiii1111144444444444444444444444444444444441");
       query2.setFirstResult((pageNum-1)*8);
       query2.setMaxResults(8); 
       
       
         List gradeList=query2.list();
         return   gradeList;  
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
//         ArrayList<StudentClasses> stc=new ArrayList<StudentClasses>();
//         ArrayList<Classes> clas=new ArrayList<Classes>();
//         
//                           Iterator it = tt.iterator();       
//                      while (it.hasNext()) {       
//                             Object[] tuple = (Object[]) it.next();    
//                             
//                              Classes  classes=(Classes)tuple[1];
//       
//                       StudentClasses  sc=(StudentClasses)tuple[0];
//                             
//                             Members members = (Members) tuple[ 0 ];       
//                   String className = (String) tuple[ 1 ];       
//               }   
//         
//         
//       
//         
//       Grade grade=new Grade();
//       
//        
//         Logger.getLogger(this.getClass().getName()).log(Level.INFO,"dsghkkkkkkoooooooooooooooooooooo");
//        session.close();
//        return grade;

    
    
         }
    
}
